<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>singleBook</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <!--    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"-->
    <!--          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"/>-->
    <!--    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>-->
    <link rel="stylesheet" th:href="@{/bootstrap.min.css}" />
    <script th:src="@{/vue.js}"></script>
</head>
<body>

<div class=" navbar navbar-default navbar-fixed-top" id="publicHeaderApp" th:fragment="publicHeader">
    <div class="container-fluid" >

        <div class="row">
            <div class="col-md-12 text-center" style="background-color: cornflowerblue; color: white">
                <a th:href="@{/}" style="color: white"><h3>蜗牛书店</h3></a>
            </div>
        </div>


        <div class="row" style="margin-top: 10px;margin-bottom: 10px">

            <div class="col-md-4 text-center">
                <button class="btn btn-primary" data-toggle="modal" data-target="#myModal" @click="clearAddForm">新增图书</button>
            </div>

        </div>

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">新增图书</h4>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group">
                                <label for="typeId">图书类型</label>
                                <select class="form-control" id="typeId" placeholder="请选择类型" v-model="typeId">
                                    <option value="-1">请选择类型</option>
                                    <option v-for="bookType in bookTypes" :value="bookType.id" v-text="bookType.name"></option>
                                </select>
                            </div>

                            <div class="form-group">
                                <label for="name">书名</label>
                                <input type="text" v-model="name" class="form-control" id="name" placeholder="请输入书名">
                            </div>

                            <div class="form-group">
                                <label for="provider">出版社</label>
                                <input type="text" v-model="provider" class="form-control" id="provider" placeholder="请输入出版社">
                            </div>

                            <div class="form-group">
                                <label for="author">作者</label>
                                <input type="text" v-model="author" class="form-control" id="author" placeholder="请输入作者名">
                            </div>
                            <div class="form-group">
                                <label for="price">价格</label>
                                <input type="text" v-model="price" class="form-control" id="price" placeholder="请输入价格">
                            </div>
                            <div class="form-group">
                                <label for="detail">描述</label>
                                <input type="text" v-model="detail" class="form-control" id="detail" placeholder="请输入描述">
                            </div>
                            <!--                            <div class="form-group">-->
                            <!--                                <input type="file" v-model="imgsrc" class="form-control">-->
                            <!--                            </div>-->
                            <div class="form-group">
                                <label for="storecount">库存数量</label>
                                <input type="text" v-model="storecount" class="form-control" id="storecount" placeholder="请输入库存">
                            </div>
                        </form>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" @click.prevent="saveBook">保存</button>
                    </div>
                </div>
            </div>
        </div>

    </div>

</div>



<div class="container-fluid" id="app" style="margin-top: 180px;margin-bottom: 100px">

    <div class="container">
    <div class="row">

        <div class="col-md-4">
            <div class="thumbnail">
                <img th:src="${book.imgsrc}" alt="...">
            </div>
        </div>
        <div class= "col-md-8">
            <p>书名 : <span th:text="${book.name}"></span></p>
            <p>作者 : <span th:text="${book.author}"></span></p>
            <p>出版社 : <span th:text="${book.provider}"></span></p>
            <p>价格 : <span th:text="${book.price} + '元'"></span></p>
            <p>简介 : <span th:text="${book.detail}"></span></p>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <a class="btn btn-success"  @click.prevent="updateBook(bookId)">修改</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a class="btn btn-success"  @click.prevent="deleteBook(bookId)">删除</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
    </div>

    </div>

</div>

<script>


    new Vue({
        el: "#app"
        ,
        data: {
            bookId:[[${book.id}]]

        }
        ,
        methods: {

            updateBook(bookId) {

                let _this = this;

                let params = {
                    typeId:_this.typeId,
                    name:_this.name
                }
                $.post("/book/update",params,function () {

                })
            }
            ,
            deleteBook(bookId) {
                $.get("/book/delete?bookId=" + bookId,function () {

                })

                location.href = "/";
            }
        }
        ,
        created(){

        }

    });


</script>


<div th:insert="publicFooter"/>
<script th:src="@{/publicFooter.js}"></script>


</body>
</html>